{% extends "base.html" %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex align-items-center justify-content-between mb-4">
        <div class="d-flex align-items-center">
            <i class="bi bi-diagram-3 fs-3 text-primary me-2"></i>
            <h2 class="mb-0">业务层级配置</h2>
        </div>
        <div class="d-flex gap-2">
            <a href="{{ url_for('hierarchy.export_hierarchy') }}" class="btn btn-outline-success">
                <i class="bi bi-file-earmark-excel"></i> 导出Excel
            </a>
            <a href="{{ url_for('hierarchy.create') }}" class="btn btn-primary">
                <i class="bi bi-plus-circle"></i> 添加层级
            </a>
        </div>
    </div>

    <!-- 筛选和统计 -->
    <div class="row g-3 mb-4">
        <div class="col-md-4">
            <div class="input-group search-bar">
                <span class="input-group-text"><i class="bi bi-search"></i></span>
                <input type="text" class="form-control" placeholder="搜索编码或名称...">
            </div>
        </div>
        <div class="col-md-8 d-flex gap-2 justify-content-end">
            <select class="form-select" style="width: auto;">
                <option>全部状态</option>
                <option>启用</option>
                <option>停用</option>
            </select>
            <button class="btn btn-outline-secondary">批量操作</button>
            <button class="btn btn-outline-secondary">导入</button>
        </div>
    </div>

    <div class="card shadow-sm">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="table-light">
                        <tr>
                            <th class="ps-4">层级</th>
                            <th>编码</th>
                            <th>名称</th>
                            <th>版本</th>
                            <th>状态</th>
                            <th class="text-end pe-4">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for hierarchy in hierarchies %}
                        <tr>
                            <td class="ps-4">
                                <span class="badge bg-info">{{ hierarchy.level }}</span>
                            </td>
                            <td>
                                <code>{{ hierarchy.code }}</code>
                            </td>
                            <td>
                                <div class="d-flex align-items-center">
                                    <i class="bi bi-building me-1"></i>
                                    {{ hierarchy.name }}
                                </div>
                            </td>
                            <td>v{{ hierarchy.version }}</td>
                            <td>
                                <span class="badge bg-{% if hierarchy.is_active %}success{% else %}secondary{% endif %} rounded-pill">
                                    {{ '启用' if hierarchy.is_active else '停用' }}
                                </span>
                            </td>
                            <td class="text-end pe-4">
                                <div class="d-flex justify-content-end gap-1">
                                    <a href="{{ url_for('hierarchy.edit', node_id=hierarchy.node_id) }}" 
                                       class="btn btn-sm btn-outline-primary">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    <a href="{{ url_for('hierarchy.tree_view') }}" 
                                       class="btn btn-sm btn-outline-info">
                                        <i class="bi bi-diagram-3"></i>
                                    </a>
                                    <form action="{{ url_for('hierarchy.delete', node_id=hierarchy.node_id) }}" 
                                          method="post" class="d-inline">
                                        <button type="submit" class="btn btn-sm btn-outline-danger"
                                                onclick="return confirm('确定删除此层级？')">
                                            <i class="bi bi-trash"></i>
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                        {% else %}
                        <tr>
                            <td colspan="6" class="text-center py-5">
                                <i class="bi bi-inbox fs-1 text-muted"></i>
                                <p class="mt-2 text-muted">暂无业务层级配置，请先添加</p>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            
            <!-- 分页导航 -->
            <nav aria-label="分页导航" class="mt-3 px-4 pb-3">
                <ul class="pagination justify-content-center">
                    <li class="page-item disabled">
                        <a class="page-link" href="#" tabindex="-1" aria-disabled="true">上一页</a>
                    </li>
                    <li class="page-item active" aria-current="page">
                        <a class="page-link" href="#">1</a>
                    </li>
                    <li class="page-item">
                        <a class="page-link" href="#">2</a>
                    </li>
                    <li class="page-item">
                        <a class="page-link" href="#">3</a>
                    </li>
                    <li class="page-item">
                        <a class="page-link" href="#">下一页</a>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
</div>
{% endblock %}